//
//  WelcomeViewController.swift
//  MyWeibo
//
//  Created by tanchao on 15/8/2.
//  Copyright © 2015年 chaoren. All rights reserved.
//

import UIKit
import SDWebImage
class WelcomeViewController: UIViewController {
    private var iconViewBottomCons:NSLayoutConstraint?
    override func viewDidLoad() {
        super.viewDidLoad()
        prepareUI()
        if let urlstr = UserAccount.sharedAccount?.avatar_large{
            iconView.sd_setImageWithURL(NSURL(string: urlstr))
        }
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        iconViewBottomCons?.constant = -UIScreen.mainScreen().bounds.height - iconViewBottomCons!.constant
    
        UIView.animateWithDuration(1.2, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5.0, options: UIViewAnimationOptions(rawValue: 0) , animations: { () -> Void in
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                NSNotificationCenter.defaultCenter().postNotificationName(WeiboRootViewControllerSwitchNotification, object: true)
        }
    }
    private func prepareUI() {
        view.addSubview(backgroudImageView)
        view.addSubview(iconView)
        view.addSubview(welcomeLabel)
        backgroudImageView.ff_Fill(view)
        let cons = iconView.ff_AlignInner(type: ff_AlignType.BottomCenter, referView: view, size: CGSize(width: 90, height: 90), offset: CGPoint(x: 0, y: -160))
        iconViewBottomCons = iconView.ff_Constraint(cons, attribute: NSLayoutAttribute.Bottom)
        welcomeLabel.ff_AlignVertical(type: ff_AlignType.BottomCenter, referView:iconView, size: nil, offset: CGPoint(x: 0, y: 16))
    }
//    MARK:- 懒加载控件
//    背景图片
    lazy private  var backgroudImageView : UIImageView = UIImageView(image: UIImage(named: "ad_background"))
//    用户头像
    lazy private  var iconView: UIImageView = {
        let ic = UIImageView(image: UIImage(named: "avatar_default_big"))
        ic.layer.masksToBounds = true
        ic.layer.cornerRadius = 45
        return ic
        }()
//   消息文字
    lazy private  var welcomeLabel:UILabel = {
        let label = UILabel()
        label.text = "欢迎归来"
        label.textColor = UIColor.darkGrayColor()
        label.sizeToFit()
        return label
        }()

}
